package bean;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import model.Cbo;
import dao.DAOCbo;


@ManagedBean(name="MBCbo")
@SessionScoped
public class MBCbo {
	private Cbo beanCBO;
	private DAOCbo daoCBO;
	private DataModel<Cbo> listaCbo;
	
	public MBCbo(){
		beanCBO = new Cbo();
		daoCBO = new DAOCbo();
	}

	public Cbo getBeanCBO() {
		return beanCBO;
	}

	public void setBeanCBO(Cbo beanCBO) {
		this.beanCBO = beanCBO;
	}

	public DAOCbo getDaoCBO() {
		return daoCBO;
	}

	public void setDaoCBO(DAOCbo daoCBO) {
		this.daoCBO = daoCBO;
	}
	
	public void save(){
		daoCBO.save(beanCBO);
		beanCBO = new Cbo();
	}
	
	public DataModel<Cbo> getListarCbo(){
		List<Cbo> list = daoCBO.listar();
		listaCbo = new ListDataModel<Cbo>(list);
		return listaCbo;
	}
	
	public void update(){
		daoCBO.update(beanCBO);
	}
	
	public void delete(){
		beanCBO = (Cbo)(listaCbo.getRowData());		
		daoCBO.delete(beanCBO);
	}
	
	public String prepararUp(){
		beanCBO = (Cbo)(listaCbo.getRowData());
		return "/amb.adm/alterarCBO.jsf";
	}
}